package com.mes.check.dao;

import org.springframework.stereotype.Repository;

import com.mes.check.dao.iface.ICheckBillDao;
import com.mes.check.domain.CheckBill;
import com.mes.common.dao.BasicDao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;

@Repository
public class CheckBillDao extends BasicDao<CheckBill> implements ICheckBillDao{
	private static final Log log = LogFactory.getLog(CheckBillDao.class);

	@Override
	public List<CheckBill> getCheckBillsByCheckTaskUid(String checkTaskUid)
			throws Exception {
		List list=null;
		try {
			log.info("++++++++++++++++++++++++++++++++++++getChecksByCheckTaskUid");
			Session session=this.getSession();
			StringBuilder hql=new StringBuilder();
			hql.append(" from " + CheckBill.class.getName()  + " where ");
			hql.append( " checkTaskUid=? ");
			Query query = session.createQuery(hql.toString());
			query.setString(0, checkTaskUid);

			list = query.list();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	@Override
	public List<CheckBill> getCheckBillsByTaskUidCheckType(String taskUid, int checkType) {
		List list = null;
		try {
			log.info("++++++++++++++++++++++++++++++++++++getChecksByTaskUidCheckType");
			Session session=this.getSession();
			StringBuilder hql=new StringBuilder();
			hql.append(" from " + CheckBill.class.getName() + " where ");
			hql.append( " taskUid=? and checkType=? ");
			Query query = session.createQuery(hql.toString());
			query.setString(0, taskUid);
			query.setInteger(1, checkType);
			
			list = query.list();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return list;
	}
	
}
